package com.yuke.cloud.service.omc.service.impl;

import com.yuke.cloud.common.core.support.BaseService;
import com.yuke.cloud.service.api.smc.dto.ShopInfoDto;
import com.yuke.cloud.service.api.smc.service.SmcFeignApi;
import com.yuke.cloud.service.omc.dao.OdsDepositMapper;
import com.yuke.cloud.service.omc.dto.OdsDepositDto;
import com.yuke.cloud.service.omc.entity.OdsDeposit;
import com.yuke.cloud.service.omc.service.OdsDepositService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;


/**
 * Created by zn on 2020/10/22.
 */
@Service
@Transactional
public class OdsDepositServiceImpl extends BaseService<OdsDeposit> implements OdsDepositService {
    @Resource
    private OdsDepositMapper odsDepositMapper;
    @Resource
    private SmcFeignApi smcFeignApi;

    @Override
    public List<OdsDepositDto> selectDepositByCondition(OdsDepositDto odsDepositDto){
        return odsDepositMapper.selectDepositByCondition(odsDepositDto);
    }

    @Override
    public List<OdsDepositDto> selectDepositExtra(List<OdsDepositDto> odsDepositDtoList){
        List<Long> shopIds = odsDepositDtoList.stream().map(OdsDepositDto::getShopId).collect(Collectors.toList());
        List<ShopInfoDto> shopInfoDtoList = smcFeignApi.getShopInfoByShopIds(shopIds);
        if (shopInfoDtoList == null || shopInfoDtoList.size() < 1){
            return odsDepositDtoList;
        }

        for (OdsDepositDto item : odsDepositDtoList){
            for (ShopInfoDto shopInfoDto : shopInfoDtoList){
                if (item.getShopId().equals(shopInfoDto.getShopId())) {
                    item.setShopName(shopInfoDto.getShopName());
                }
            }

        }
        return odsDepositDtoList;
    }
}
